package controllers.pc.users;


import models.System.Headline.SystemTitle;
import models.Models.ShopReharges;
import models.SystemModels.SystemUser;
import net.sf.json.JSONObject;

import java.util.List;

/**
 * Created by Administrator on 2018-07-29.
 * 充值
 */
public class Recharges extends Recharge {

    public static void SystemCompensation(){
        JSONObject jsonObject = new JSONObject();
        try {
            ShopReharges shopReharges = new ShopReharges();
            shopReharges.name=id();
            shopReharges.number=params.get("number");
            shopReharges.price= params.get("price");
            shopReharges.SystemTitle = SystemTitle.SystemCompensation;
            if (models.System.Recharge.Recharge.ShopReharge(shopReharges)){
                jsonObject.put("code",1);
                renderJSON(jsonObject);
            }else{
              jsonObject.put("code", 0);
                renderJSON(jsonObject);
            }
        }catch (Exception ex){
            jsonObject.put("code", -1);
            renderJSON(jsonObject);
        }
    }

    public static void SystemNormalRecharge(){
        JSONObject jsonObject = new JSONObject();
        try {
            ShopReharges shopReharges = new ShopReharges();
            shopReharges.name=id();
            shopReharges.number=params.get("number");
            shopReharges.price= params.get("price");
            shopReharges.SystemTitle = SystemTitle.SystemNormalRecharge;
            if (models.System.Recharge.Recharge.ShopReharge(shopReharges)){
                jsonObject.put("code",1);
                renderJSON(jsonObject);
            }else{
                jsonObject.put("code", 0);
                renderJSON(jsonObject);
            }
        }catch (Exception ex){
            jsonObject.put("code", -1);
            renderJSON(jsonObject);
        }
    }

    public static void SystemDistribution(){
        JSONObject jsonObject = new JSONObject();
        try {
            ShopReharges shopReharges = new ShopReharges();
            shopReharges.name=id();
            shopReharges.number=params.get("number");
            shopReharges.price= params.get("price");
            shopReharges.SystemTitle = SystemTitle.SystemDistribution;
            if (models.System.Recharge.Recharge.ShopReharge(shopReharges)){
                jsonObject.put("code",1);
                renderJSON(jsonObject);
            }else{
                jsonObject.put("code", 0);
                renderJSON(jsonObject);
            }
        }catch (Exception ex){
            jsonObject.put("code", -1);
            renderJSON(jsonObject);
        }
    }

    public static void SystemRechargeTitle(){
        JSONObject jsonObject = new JSONObject();
        try {
            ShopReharges shopReharges = new ShopReharges();
            shopReharges.name=id();
            shopReharges.number=params.get("number");
            shopReharges.price= params.get("price");
            shopReharges.SystemTitle = SystemTitle.SystemRechargeTitle;
            if (models.System.Recharge.Recharge.ShopReharge(shopReharges)){
                jsonObject.put("code",1);
                renderJSON(jsonObject);
            }else{
                jsonObject.put("code", 0);
                renderJSON(jsonObject);
            }
        }catch (Exception ex){
            jsonObject.put("code", -1);
            renderJSON(jsonObject);
        }
    }

    public static void SystemFirstGift(){
        JSONObject jsonObject = new JSONObject();
        try {
            ShopReharges shopReharges = new ShopReharges();
            shopReharges.name=id();
            shopReharges.number=params.get("number");
            shopReharges.price= params.get("price");
            shopReharges.SystemTitle = SystemTitle.SystemFirstGift;
            if (models.System.Recharge.Recharge.ShopReharge(shopReharges)){
                jsonObject.put("code",1);
                renderJSON(jsonObject);
            }else{
                jsonObject.put("code", 0);
                renderJSON(jsonObject);
            }
        }catch (Exception ex){
            jsonObject.put("code", -1);
            renderJSON(jsonObject);
        }
    }

    public static String id(){
        String name =session.get("name");
        List<SystemUser> systemUserList = SystemUser.find("UserName",name).fetch();
        return systemUserList.get(0).Id.toString();
    }

}
